package com.tqjc.system.common.enums;

import com.tqjc.system.system.model.vo.TaskMaterialOptVO;
import com.tqjc.system.system.service.SysBusinessTaskService;
import com.tqjc.system.system.service.TaskOptService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author 86195
 * @version 1.0
 * @description 任务操作类型枚举
 * @date 2023/10/31 11:43
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum TaskTypeEnum implements TaskOptService {

    UPDATE("U","编辑成功","修改"){
        @Override
        public void handle(SysBusinessTaskService service,String msgBody,long idKey) {
            service.modify(msgBody);

        }

        @Override
        public void saveOpt(SysBusinessTaskService service, TaskMaterialOptVO materialOptVO) {
            service.optModify(materialOptVO);
        }

        @Override
        public void frontConfirm(SysBusinessTaskService service,TaskMaterialOptVO materialOptVO) {
            service.modify(materialOptVO);
        }
    },
    DELETE("D","删除成功","删除"){
        @Override
        public void handle(SysBusinessTaskService service,String msgBody,long idKey) {

        }

        @Override
        public void saveOpt(SysBusinessTaskService service, TaskMaterialOptVO materialOptVO) {

        }

        @Override
        public void frontConfirm(SysBusinessTaskService service,TaskMaterialOptVO materialOptVO) {

        }
    },
    FINISH("F","操作成功","完成"){
        @Override
        public void handle(SysBusinessTaskService service, String msgBody, long idKey) {

        }

        @Override
        public void saveOpt(SysBusinessTaskService service, TaskMaterialOptVO materialOptVO) {

        }

        @Override
        public void frontConfirm(SysBusinessTaskService service,TaskMaterialOptVO materialOptVO) {
            service.completeTask(materialOptVO.getTankCarNo(),materialOptVO.getTaskId());

        }
    },
    INCREASE("I","新增成功","新增"){
        @Override
        public void handle(SysBusinessTaskService service,String msgBody,long idKey) {
            service.increase(msgBody,idKey);
        }

        @Override
        public void saveOpt(SysBusinessTaskService service, TaskMaterialOptVO materialOptVO) {
            service.optIncrease(materialOptVO);

        }

        @Override
        public void frontConfirm(SysBusinessTaskService service,TaskMaterialOptVO materialOptVO) {
            service.increase(materialOptVO);
        }
    };

    private String type;

    /**
     * 操作成功后，给前端返回的提示语
     */
    private String successMsg;

    private String desc;


    public static TaskTypeEnum getEnumByType(String type) {

        for (TaskTypeEnum value : TaskTypeEnum.values()) {
            if(value.getType().equals(type)){
                return value;
            }

        }
        return null;
    }
}
